In this lesson, we'll see how to use native meaning comp. No duchies module's with an electron up by
building them for the specific version of electrons used in the air.
Now, whilst on the subject of using node modules, I want to stress the importance of what we covered
in the previous lesson.
With regard to the main application process being a notorious process, I very often get asked how to
use a particular technology with an electron up.
For example, how would I implement it CircuLite database in my electron up.
The obstacle in trying to figure this out is that we are not trying to implement anything in an electron
up.
Rather, we're implementing it in a standard notorious app, as the main process is simply that a no
dodgiest process started by and using the electron module.
In other words, we can use pretty much any node module from the NPM registry in the exact same way
we would any other node up.
This is a very important abstraction to make and remember as it will allow you to think in the correct
context.
So let's see an example on NPM dot com.
I'll install this colors module, a simple node module for producing coloured output in the terminal.
Back in our project directory, install the module with NPM eye colors.
That's done so now in Maine, dodgiest require that new module with consed colors equals require colors.
Logging out with the colors module in rainbow colors.
Which are quirt.
And there we have it, so a random node module used in a matter of seconds right inside of our electron
up.
The main purpose of this lesson, however, being to show you how to use native modules, a perfect
example of such a module being the secret to password hashing library.
I'll copy the most basic example of hashing a password from the docs.
Replace this log and colors module with that not forgetting to also require the decrypt module decrypt
equals require decrypt, which we still have to install and all we are doing is calling decrypt hash.
I'll make this a string.
So harshing the password, my plaintext password with 10 salt grounds and in the callback decrypt will
provide us with a hashed password, which I log out.
Save this.
Installed by corrupt locally.
And at this point, we see the module being compiled automatically by 9pm for my version of No Duchesses
V8 engine, all done without any problems clear this started up.
And it breaks electron quite unexpectedly, meaning the app crashed.
So what happened here is that electronics using a different version of notes, internal V8 engine,
then the version on my machine, meaning at the moment the script was compiled for the wrong version
and crashes.
Now, there's a number of ways to fix this.
And if you check the very last archives section of this course, you'll see one of the earlier more
manual ways of doing this.
Should you be interested in a much simpler way, however, is using the electron rebuild command line
tool.
This again comes in the form of a node module, so I'll install that globally this time.
NPM install g electron rebuild.
I'll forward through this.
Done so now, having electron rebuild available on the command line, rebuilding the already installed
decrypt module for our version of Electron is as simple as running electron rebundled decrypt.
Rebuild complete, start the up again.
This time, it launches without issue, so quiet, check back in the terminal and there.
As expected, we see the hashed password being locked out in the terminal.